{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "8fa8e168",
   "metadata": {},
   "source": [
    "## 列表练习 初始字典\n",
    "\n",
    "```\n",
    "课堂练习：\n",
    "goods = [\n",
    "    [\"10001\",\"吸尘器\",\"88\"],\n",
    "    [\"10002\",\"波霸奶茶\",\"10\"],\n",
    "    [\"10003\",\"iPhone12\",\"9999\"],\n",
    "    [\"10004\",\"法拉利\",\"400000\"],\n",
    "    [\"10005\",\"小米手环\",\"199\"]\n",
    "]\n",
    "user_shop_list = []\n",
    "\n",
    "#使用占位符\n",
    "支付宝余额 = input(\"请输入您的余额：\")\n",
    "info = '''------goods list-------\n",
    "%s\n",
    "%s\n",
    "%s\n",
    "%s\n",
    "%s\n",
    "'''%(goods[0],goods[1],goods[2],goods[3],goods[4])\n",
    "print(info)\n",
    "user_input_ID = input(\"请输入商品的ID：\")\n",
    "for good in goods:\n",
    "    print(good)\n",
    "    # 判断商品的id是否正确\n",
    "    if user_input_ID == good[0]:\n",
    "        # 判断用户的余额是否够用\n",
    "        if int(good[2]) < int(支付宝余额):\n",
    "            # 把商品加进list\n",
    "            user_shop_list.append(good)\n",
    "            # 扣除支付宝余额\n",
    "            break\n",
    "\n",
    "    else:\n",
    "        print(\"您输入的商品信息有问题，请输入正确的商品ID\")\n",
    "\n",
    "print(user_shop_list)\n",
    "```"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b82b06e6",
   "metadata": {},
   "source": [
    "### 课本内容练习\n",
    "```\n",
    "效果：“Don't panic” ==> \"on tap\"\n",
    "方法一：使用list\n",
    "phrase = \"Don't panic!\"\n",
    "plist = list(phrase)  # list() 可以将 str  to(转)  list\n",
    "print(phrase)\n",
    "print(plist)\n",
    "\n",
    "1.删除后面四个元素 a n i c\n",
    "for i in range(4):\n",
    "    plist.pop()\n",
    "print(plist)\n",
    "2. 删除 D  ‘\n",
    "plist.remove('D')\n",
    "print(plist)\n",
    "plist.pop(2)\n",
    "print(plist)\n",
    "\n",
    "3. 数学案例： 计算 （(a+b)*(c+d)）\n",
    "plist.extend([plist.pop(),plist.pop()])\n",
    "#['o','n','t',' '][ a ,p]\n",
    "print(plist)\n",
    "\n",
    "4. 数据插入  实现：’t‘ 和’ ‘ 的位置转换\n",
    "plist.insert(2,plist.pop(3))\n",
    "print(plist)\n",
    "print(plist.pop(2))  # 1，代表删除的内容的值 2，他删除了plist的这个值\n",
    "plist.insert(3,plist.pop(2))\n",
    "print(plist)\n",
    "5. list to str\n",
    "new_phrase = ''.join(plist)\n",
    "\n",
    "print(plist)\n",
    "print(new_phrase)\n",
    "```"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2f4201ec",
   "metadata": {},
   "source": [
    "```\n",
    "方法二：使用切片的方法\n",
    "phrase = \"Don't panic!\"\n",
    "plist = list(phrase)  # list() 可以将 str  to(转)  list\n",
    "print(phrase)\n",
    "print(plist)\n",
    "\n",
    "\n",
    "on_str = ''.join(plist[1:3])\n",
    "print(on_str)\n",
    "new_phrase = on_str+ ''.join(plist[5]+plist[4]+plist[7]+plist[6])\n",
    "print(plist)\n",
    "print(new_phrase)\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2fb6b8ad",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
